<style>
    .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
</style>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
			<input type="hidden" name="id" value="{{.systemSetting.Id}}" >
            <div class="layui-form-item">
                <label class="layui-form-label required">邮箱服务器地址</label>
                <div class="layui-input-block">
                    <input type="text" name="server_host" lay-verify="required" lay-reqtext="请输入邮箱服务器地址" placeholder="请输入邮箱服务器地址"  value="{{.emailSetting.Server_host}}" class="layui-input">
                    <tip>填写邮箱服务器地址，如腾讯企业邮箱为 smtp.exmail.qq.com</tip>
                </div>
            </div>
			
              <div class="layui-form-item">
                <label class="layui-form-label required">邮箱服务器端口</label>
                <div class="layui-input-block">
                    <input type="text" name="server_port" lay-verify="required" lay-reqtext="请输入邮箱服务器端口" placeholder="请输入邮箱服务器端口"  value="{{.emailSetting.Server_port}}" class="layui-input">
                    <tip>填写邮箱服务器端口，如腾讯企业邮箱为 465（阿里云不支持25端口，建议使用465）</tip>
                </div>
            </div>
			<div class="layui-form-item">
                <label class="layui-form-label required">发件人邮箱</label>
                <div class="layui-input-block">
                    <input type="text" name="from_email" lay-verify="required" lay-reqtext="请输入发件人邮箱" placeholder="请输入发件人邮箱"  value="{{.emailSetting.From_email}}" class="layui-input">
                    <tip>填写发件人邮箱，用来发邮件的邮箱（需开启POP3/smtp服务连接接方式选ssl）</tip>
                </div>
            </div>
			<div class="layui-form-item">
                <label class="layui-form-label required">发件人邮箱密码</label>
                <div class="layui-input-block">
                    <input type="text" name="from_passwd" lay-verify="required" lay-reqtext="请输入发件人邮箱密码" placeholder="请输入发件人邮箱密码"  value="{{.emailSetting.From_passwd}}" class="layui-input">
                    <tip>填写发件人邮箱密码，如 k35Hxxxf52s7T32R</tip>
                </div>
            </div>
			
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="setting">确认保存</button>
					<button class="layui-btn" id="test_email">测试邮件</button>
				</div>
				 
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form','miniPage'], function () {
        var form = layui.form
            , layer = layui.layer;
		$ = layui.$;
		miniPage = layui.miniPage;
        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        //监听提交
        form.on('submit(setting)', function (data) {
            /*parent.layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            });*/
			var url = "/admin/emailSet"
            $.post(url,data.field,function(resp){
				
				if(resp.code == 0){
					//成功
					layer.msg("编辑成功",{end:function(){
						location.reload();
						// 关闭弹出层
						// layer.closeAll();
					}});
					
				}else{
					layer.msg(resp.msg);
				}
		    },"json");
			
            return false;
        });
		
		//测试邮件
		$("#test_email").click(function(){
			
			var content = miniPage.getHrefContent('/admin/emailTest');
			var openWH = miniPage.getOpenWidthHeight();

			var index = layer.open({
				title: '测试邮件',
				type: 1,
				shade: 0.2,
				maxmin:true,
				shadeClose: true,
				area: [openWH[0] + 'px', openWH[1] + 'px'],
				offset: [openWH[2] + 'px', openWH[3] + 'px'],
				content: content,
			});
			$(window).on("resize", function () {
				layer.full(index);
			});
			return false;
            
		});
		
		

    });
</script>